package com.example.shop_2208.register

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.shop_2208.entity.ParamRegister
import com.example.shop_2208.entity.UserEntityResult
import com.example.shop_2208.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class RegisterViewModel:BaseViewModel() {
    val registerSuccess = MutableLiveData<UserEntityResult>()
    val registerFail = MutableLiveData<String>()
    fun register(username:String,password:String,repassword:String){
        viewModelScope.launch {
            try {
                val param = ParamRegister(username, password, repassword)
                registerSuccess.value = apiServer.register(param)
            }catch (e:Exception){
                registerFail.value = e.message
            }
        }
    }
}